<template>
  <dl>
    <dd>
      <div>
        <span class="tit">发布时间：</span>
        <el-select v-model="form.registered_date" placeholder="请选择">
          <el-option
            v-for="item in option.registered_date"
            :key="item.key"
            :label="item.label"
            :value="item.key">
          </el-option>
        </el-select>
      </div>
      <div>
        <span class="tit">产业：</span>
        <el-select v-model="form.achievement_industry" placeholder="请选择">
          <el-option
            v-for="item in option.achievement_industry"
            :key="item.key"
            :label="item.label"
            :value="item.key">
          </el-option>
        </el-select>
      </div>
    </dd>
    <dd>
      <span class="tit">类型：</span>
      <p class="cont">
        <span v-for="(item, index) in option.achievement_type" :key="index" :class="{active: form.achievement_type === item.key}" @click="handleChangeItem('achievement_type', item)">{{item.key}}</span>
      </p>
    </dd>
    <dd>
      <span class="tit">机构：</span>
      <p class="cont">
        <span v-for="(item, index) in option['achievement_institution']" :key="index" :class="{active: form['achievement_institution'] === item.key}" @click="handleChangeItem('achievement_institution', item)">{{item.key}}</span>
      </p>
    </dd>
  </dl>
</template>

<script>
export default {
  data() {
    return {
      form: {
        registered_date: '全部', // 发布时间
        achievement_industry: '全部', // 产业
        achievement_type: '全部', // 类型
        achievement_institution: '全部', // 机构
      },
      option: {
        registered_date: [],
        achievement_industry: [],
        achievement_institution: [],
        achievement_type: []
      },
    }
  },
  methods: {
    init(agg) {
      // 发布时间
      let registered_date = [{key: '全部'}]
      registered_date = [
        ...registered_date,
        ...agg.registered_date.map(v => {
          return {
            label: moment(v.key).format('YYYY'),
            key: v.key,
            doc_count: v.doc_count
          }
        })
      ]
      this.$set(this.option, 'registered_date', registered_date)
      // 产业
      this.$set(this.option, 'achievement_industry', [{key: '全部'}, ...agg.achievement_industry])
      // 类型
      this.$set(this.option, 'achievement_type', [{key: '全部'}, ...agg.achievement_type])
      // 机构
      this.$set(this.option, 'achievement_institution', [{key: '全部'}, ...agg['achievement_institution']])
    },
    handleChangeItem(param, item) {
      this.$set(this.form, param, item.key)
    },
    reset() {
      this.form = {
        registered_date: '全部', // 发布时间
        achievement_industry: '全部', // 产业
        achievement_type: '全部', // 类型
        achievement_institution: '全部', // 机构
      }
    }
  },
  watch: {
    form: {
      handler(newVal, oldVal) {
        this.$emit('getParams', this.form)
      },
      deep: true
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
</style>